package com.aurora.source.base;

import android.annotation.SuppressLint;
import android.graphics.Color;
import android.os.Bundle;
import android.support.annotation.LayoutRes;
import android.support.v4.content.ContextCompat;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.FrameLayout;

import com.aurora.source.R;
import com.aurora.source.util.SPUtils;
import com.aurora.source.widget.SimpleToolbar;
import com.bigkoo.pickerview.builder.OptionsPickerBuilder;
import com.bigkoo.pickerview.listener.OnOptionsSelectListener;
import com.bigkoo.pickerview.view.OptionsPickerView;

import butterknife.BindColor;


/**
 * Base Back Activity
 * <p>
 * Created by Lance
 * 2018/07/06.
 */
public abstract class BaseToolbarActivity<T extends BasePresenter> extends BaseActivity<T> {

    @BindColor(R.color.white)
    public int white;

    public static final int SELECT_COMPERE = 5;// 主持人
    public static final int SELECT_ATTENDEES = 6;// 参会人员
    public static final int SELECT_RECORD = 7;// 记录人员
    public static final int SELECT_REVIEWERS = 8;// 审核人员
    public static final int DEPARTMENT_LIST = 9;// 所属部门

    public int pageNo = 0;// 当前页码
    public int pageSize = 20;// 默认每页十条,可不传

    public Bundle bundle;// bundle 传递数据

    protected FrameLayout mFlActivityContainer;

    public SimpleToolbar simpleToolbar;// Toolbar

    @SuppressLint("ResourceType")
    @Override
    protected void setBaseView(@LayoutRes int layoutId) {
        try {
            mContentView = LayoutInflater.from(this).inflate(R.layout.activity_back, null);
            setContentView(mContentView);
            mFlActivityContainer = findViewById(R.id.fl_activity_container);
            simpleToolbar = findViewById(R.id.st_toolbar);
            simpleToolbar.setLeftTitleClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View view) {
                    hideSoftInput();
                    finish();
                }
            });

            if (layoutId > 0) {
                mFlActivityContainer.addView(LayoutInflater.from(this).inflate(layoutId, mFlActivityContainer, false));
            }

            userId = String.valueOf(SPUtils.get(activity, SPUtils.USER_ID, ""));

            bundle = new Bundle();
        } catch (Exception e) {
            e.printStackTrace();
        }
    }



    // 选择城市三级联动
    public void selectDestination(OnOptionsSelectListener optionsSelectListener) {
        try {
            OptionsPickerView pvOptions = new OptionsPickerBuilder(activity, optionsSelectListener)
                    .setTitleText("地区选择")
                    .setTextColorCenter(Color.BLACK) //设置选中项文字颜色
                    .setSubCalSize(18)//确定和取消文字大小
                    .setTitleSize(20)//标题文字大小
                    .setContentTextSize(18)//滚轮文字大小
                    .setTitleBgColor(ContextCompat.getColor(activity, R.color.whitegray))//标题背景颜色 Night mode
                    .setCyclic(true, false, false)//循环与否
                    .setSelectOptions((int) SPUtils.get(activity, "PROVINCE_DESTINATION", 0),
                            (int) SPUtils.get(activity, "CITY_DESTINATION", 0), (int) SPUtils.get(activity, "DISTRICT_DESTINATION", 0))  //设置默认选中项
                    .setTextColorCenter(Color.BLACK) //设置选中项文字颜色
                    .setOutSideCancelable(false)// default is true
                    .build();

            pvOptions.setPicker(application.provinceNames, application.cityNames, application.areaNames);//三级选择器
            pvOptions.show();
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}
